package com.sen.demo.controller;

import com.sen.demo.MQ.ActiveMQClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @className: LoginController
 * @Auther: jiesen.liu
 * @Date: 2019/7/15 10:52
 * @package: com.sen.demo
 */
@Slf4j
@Controller()
public class LoginController {

    @Autowired(required = false)
    ActiveMQClient activeMQClient;



    @RequestMapping("/index")
    public String index(Model model, HttpServletRequest request) {
        String url = request.getServerName()
                + ":" + request.getServerPort()+ request.getContextPath();
        model.addAttribute("url", url);
        return "index";
    }


    @RequestMapping("/send")
    @ResponseBody
    public String send (@RequestParam("name") String value) {
        activeMQClient.send("name", value);
        return "success";
    }

    @ResponseBody
    @RequestMapping(value = "/indexName", produces = { "application/json;charset=UTF-8" })
    public String index(@RequestParam("name") String name) {
        log.error("helloWorld：" + name);
        return "helloWorld:" + name;
    }
}
